package com.chapter.sample.jvm.gc.escape;

/**
 * 标量替换
 *
 * 结论:
 *      java中的逃逸分析，其实优化的点就在于堆栈上分配的对象进行标量替换
 */
public class ScalarReplace {
    public static class User {
        private int id;
        private String name;
    }
    public static void alloc() {
        User u = new User();//未发生逃逸
        u.id = 5;
        u.name = "www.baidu.com";
    }
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            alloc();
        }
        long end = System.currentTimeMillis();
        System.out.println("花费的时间为：" + (end - start) + "ms");
    }
}
